package com.viknix.threadpool.manager.client.util;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: Dongqi
 * @Date: 2021/10/23 17:19
 * @Version 1.0
 * @Description: 线程池工具
 */
@Slf4j
public class ThreadpoolUtil {

    public static void printThreadPoolParam(ThreadPoolExecutor threadPoolExecutor) {
        log.info(">>> CorePoolSize:{}, " +
                        "MaximumPoolSize:{}, " +
                        "KeepAliveTime:{} ms, " +
                        "ThreadFactory:{}, " +
                        "RejectedExecutionHandler:{}, " +
                        "ActiveCount:{}, " +
                        "PoolSize:{}, " +
                        "LargestPoolSize:{}, " +
                        "CompletedTaskCount:{}, " +
                        "TaskCount:{}",
                threadPoolExecutor.getCorePoolSize(),
                threadPoolExecutor.getMaximumPoolSize(),
                threadPoolExecutor.getKeepAliveTime(TimeUnit.MILLISECONDS),
                threadPoolExecutor.getThreadFactory(),
                threadPoolExecutor.getRejectedExecutionHandler(),
                // 返回正在执行任务的线程的大致数量
                threadPoolExecutor.getActiveCount(),
                // 返回池中当前的线程数
                threadPoolExecutor.getPoolSize(),
                // 返回曾经同时进入池中的最大线程数。
                threadPoolExecutor.getLargestPoolSize(),
                // 返回已完成执行的大致任务总数。近似值，但在连续调用中永远不会减少
                threadPoolExecutor.getCompletedTaskCount(),
                // 返回已安排执行的大致任务总数。近似值
                threadPoolExecutor.getTaskCount());
    }
}
